var HuoYuePaikeCheckedItems;
var data_data;
var _items = ["leiji","active_user","huoyuelv"]
var _itemscn = ["累计用户数","活跃用户数","活跃率"]
function getHuoYuePaikeData() {
    
    var _url
    if ($("#HuoYuePaikedaZhou").hasClass("selbitem")){
    
       _url = "activeweek";
       var osID = document.getElementById("HuoYuePaikeOSZhou").options[document.getElementById("HuoYuePaikeOSZhou").selectedIndex].value;
    var typeID = document.getElementById("HuoYuePaikeTypeZhou").options[document.getElementById("HuoYuePaikeTypeZhou").selectedIndex].value;
    
    var startDate = $("#HuoYuePaikeStartDateZhou").attr("per");
	var endDate = $("#HuoYuePaikeEndDateZhou").attr("per");
    
    }else{
    
       _url = "activemonth";
       
       var osID = document.getElementById("HuoYuePaikeOSYue").options[document.getElementById("HuoYuePaikeOSYue").selectedIndex].value;
    var typeID = document.getElementById("HuoYuePaikeTypeYue").options[document.getElementById("HuoYuePaikeTypeYue").selectedIndex].value;
    
    var startDate = $("#HuoYuePaikeStartDateYue").attr("per");
	var endDate = $("#HuoYuePaikeEndDateYue").attr("per");
    
    }

    
    
        
    
    
   

	$(".HuoYuePaikeChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/"+_url+"?sDate="+startDate+"&tt=2&eDate="+endDate;
	        
            
            if (osID != ""){
				APIurl += "&os="+osID;
            }
			if (typeID != ""){
				APIurl += "&dt="+typeID;
            }
            

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loadHuoYuePaikeData(data)}
			});
            
            
            $.ajax({
  url: APIurl,
  type: "POST",
  data: "username="+login_username,
success: function(msg){
   //alert('ok');
}
});
		

	}
	else {
		alert("请选择时间区域");
	}
}


var HuoYuePaikeTabArr, HuoYuePaikeDetailArr, HuoYuePaikeSumArr, HuoYuePaikeDateArr, MainSubTitle;
function loadHuoYuePaikeData(data) {
    
    
    jQuery('#body-wrapper').hideLoading();
    if(data['zongji'] != "0"){
    
    if ($("#HuoYuePaikedaZhou").hasClass("selbitem")){
    
       var osID = document.getElementById("HuoYuePaikeOSZhou").options[document.getElementById("HuoYuePaikeOSZhou").selectedIndex].value;
    var typeID = document.getElementById("HuoYuePaikeTypeZhou").options[document.getElementById("HuoYuePaikeTypeZhou").selectedIndex].value;
    
    var startDate = $("#HuoYuePaikeStartDateZhou").val();
	var endDate = $("#HuoYuePaikeEndDateZhou").val();
    
    }else{
    
       
       var osID = document.getElementById("HuoYuePaikeOSYue").options[document.getElementById("HuoYuePaikeOSYue").selectedIndex].value;
    var typeID = document.getElementById("HuoYuePaikeTypeYue").options[document.getElementById("HuoYuePaikeTypeYue").selectedIndex].value;
    
    var startDate = $("#HuoYuePaikeStartDateYue").val();
	var endDate = $("#HuoYuePaikeEndDateYue").val();
    
    }
    
    data_data = data;
	var tab = "";
	
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	HuoYuePaikeTabArr = new Array();
	HuoYuePaikeDetailArr = new Array();
	HuoYuePaikeSumArr = new Array();
	HuoYuePaikeDateArr = new Array();

			//显示选择Tab
			
            if(osID==""){

            genTabsHuoYuePaike("HuoYuePaike", "HuoYuePaikeOSZhou", HuoYuePaikeTabArr, HuoYuePaikeDetailArr, HuoYuePaikeSumArr, HuoYuePaikeCheckedItems,0);
        }else if(typeID == ""){

            genTabsHuoYuePaike("HuoYuePaike", "HuoYuePaikeTypeZhou", HuoYuePaikeTabArr, HuoYuePaikeDetailArr, HuoYuePaikeSumArr, HuoYuePaikeCheckedItems,0);
        }else{ genTabsHuoYuePaike("HuoYuePaike","", HuoYuePaikeTabArr, HuoYuePaikeDetailArr, HuoYuePaikeSumArr, HuoYuePaikeCheckedItems,0);  }
			
            
            //读取数据
            
        if ($("#HuoYuePaikeLineTab").hasClass("selbitem")){
            
			changeChartType('HuoYuePaike', 'Line');
        }
        
        if ($("#HuoYuePaikeTableTab").hasClass("selbitem")){
            
			changeChartType('HuoYuePaike','Table');
        }
        
        if (!$("#HuoYuePaikeTableTab").hasClass("selbitem") && !$("#HuoYuePaikeLineTab").hasClass("selbitem")){
            
			changeChartType('HuoYuePaike','Line');
        }
        
        
        
        //生成表格
        genSummaryTable_HuoYuePaike("HuoYuePaikeTable",_itemscn,data['All']['table'],NewMainVideoSumArr,"总览","");
        
        
        //生成线形图
        genSelLineChart_HuoYuePaike(_items,_itemscn,"HuoYuePaikeLine",data['All']['xiany'],data['All']['xianx'],_itemscn);
        
        
    }else{ alert("选择的时间区间内无数据");	 }
		
	
}

function changeHuoYuePaikeTab(tabName,optionName) {
	
        
        
        genSummaryTable_HuoYuePaike("HuoYuePaikeTable",_itemscn,data_data[tabName]['table'],NewMainVideoSumArr,tabName,HuoYuePaikeTabArr);
        
       //生成线形图
        genSelLineChart_HuoYuePaike(_items,_itemscn,"HuoYuePaikeLine",data_data[tabName]['xiany'],data_data[tabName]['xianx'],_itemscn);
    
    
	$(".bitem").removeClass("selbitem");
	$("#HuoYuePaikeTab"+tabName).addClass("selbitem");	
    
    
    
	
}


function changehuoyuepaikeda(cname){
   
     
    
    $(".HuoYuePaikechang").hide();
    
   
    $("#HuoYuePaike"+cname).show();
        
            
    $(".bitemhuoyuepaike").removeClass("selbitem");
	$("#HuoYuePaikeda"+cname).addClass("selbitem");
    
    getHuoYuePaikeData();


}

function changehuoyuepaikexian(cname){
   
     
    
    $(".huoyuepaikexiandiv").hide();
    
   
    $("#HuoYuePaikeLine"+cname).show();
        
            
    $(".bitemhuoyuepaikexian").removeClass("selbitem");
	$("#HuoYuePaikexian"+cname).addClass("selbitem");


}




